package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonRealeaseSpeakDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.ui.activity.CartoonDetailActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.fragment.CartoonSentenceSpeakFragment;
import com.fancy.learncenter.utils.FileUtils;
import com.fancy.learncenter.utils.TimeUtil;

import java.util.List;

/**
 * Created by shiweiwei on 2017/12/7.
 */

public class CartoonExpandListenReleaseAdapter extends CommonRecycleViewAdapter<CartoonRealeaseSpeakDataBean.ResultBean> {

    public CartoonExpandListenReleaseAdapter(Context mContext, List<CartoonRealeaseSpeakDataBean.ResultBean> itemDatas) {
        super(mContext, R.layout.fragment_cartoon_local_item, itemDatas);
    }


    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonRealeaseSpeakDataBean.ResultBean item, int position) {
        TextView title = customViewHold.getView(R.id.title);
        title.setText(item.getQuestionName());

        TextView duration = customViewHold.getView(R.id.duration);
        duration.setText(TimeUtil.localDubTimeLength(Integer.parseInt(item.getResourceDuration())));

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getCommitTime());

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getCoverImgUrl());


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CartoonDetailActivity.class);
                intent.putExtra(CartoonDetailActivity.QUESTION_ID, item.getSubjectQuestionId());
                intent.putExtra(CartoonDetailActivity.ANSWER_KEY, item.getAnswerResourceUrls().get(0));
                intent.putExtra(CartoonDetailActivity.LOCAL_FILE_PATH, FileUtils.getExpandRecorderAudioPath() + item.getSubjectQuestionId() + Constant.DIVID_CODE + item.getCommitTime().split(" ")[0] + Constant.DIVID_CODE + CartoonSentenceSpeakFragment.RELEASE_FALG + "/");
                mContext.startActivity(intent);

//                if (!TextUtils.isEmpty(item.getLocalResourceUrl())) {
//                    intent.putExtra(CartoonDetailActivity.LOCAL_FILE_PATH, item.getLocalResourceUrl());
//                } else {
//                    intent.putExtra(CartoonDetailActivity.LOCAL_FILE_PATH, item.getAnswerResourceUrls().get(0));
//                }

            }
        });
    }
}
